package com.sgb.kjwl.view.ui.adapter.pick;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.view.View;
import android.widget.TextView;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.pick.QuotationListEntity3;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

public class QuotationItemAdapter5 extends BaseRecycleAdapter<QuotationListEntity3> {

    private QuotationNumListener numListener;

    public QuotationItemAdapter5(Context context, List<QuotationListEntity3> datas) {
        super(context, R.layout.item_quotation5, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, final QuotationListEntity3 entity) {
        holder.setBinding(BR.viewModel, entity);
        if ("quantity".equals(entity.getKey())) {
            if (null != numListener) {
                numListener.setNum(entity.getValue());
            }
        } else if ("filePath".equals(entity.getKey())) {
            TextView contentView = holder.getItem().findViewById(R.id.content_view);
            Drawable drawable = context.getResources().getDrawable(R.mipmap.icn_down_load);
            drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
            contentView.setCompoundDrawables(drawable, null, null, null);
            contentView.setText("下载附件");
            contentView.setTextColor(context.getResources().getColor(R.color.color_5792FD));
            contentView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    //调用系统浏览器下载
                    Uri uri = Uri.parse(entity.getValue());
                    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                    context.startActivity(intent);
                }
            });
        }
    }

    public interface QuotationNumListener {
        void setNum(String num);
    }

    public void setNumListener(QuotationNumListener listener) {
        this.numListener = listener;
    }
}
